#include "head.h"

int Compute_file_md5(char *file_path, char *md5_str){
    int fd = open(file_path,O_RDONLY);
    ERROR_CHECK(fd,-1,"open");
    MD5_CTX c;
    MD5_Init(&c);
    char buf[4096];
    while(1){
        bzero(buf,sizeof(buf));
        ssize_t ret = read(fd,buf,sizeof(buf));
        if(ret == 0){
            break;
        }
        MD5_Update(&c,buf,ret);
    }   
    unsigned char MD[16];
    MD5_Final(MD,&c);
    for(int i = 0; i < 16; ++i){
        snprintf(md5_str + i*2,2+1,"%02x",MD[i]);
    }	
    md5_str[MD5_STR_LEN] = '\0'; // add end
	return 0;
}